﻿@using KRM.Core

@model tblOrder
@{
    var db = new KRMEntities();
    var title = Model.OrderRef + " - " + Model.CustomerEmailAddress;
    var orderref = Model.OrderRef;
    var tradeOrders = db.tblTradeCustomerOrders.FirstOrDefault(a => a.OrderId == Model.OrderID);
    if (tradeOrders != null)
    {
        title = Model.OrderRef + " - " + tradeOrders.PONumber + " - " + tradeOrders.TradeOrderRef + " - " + Model.CustomerEmail;
        orderref = Model.OrderRef + " - " + tradeOrders.PONumber + " - " + tradeOrders.TradeOrderRef;
    }

    ViewBag.Title = title;
    ViewBag.UrlLink = "/orderview/search";
    Layout = "~/Views/Shared/_Layout.cshtml";
    ViewBag.Warehouseid = new SelectList(db.tblKRMWarehouses.Where(a => a.legacy == false), "WarehouseID", "WarehouseName");
}
<script src="/js/order.js"></script>
<input type="hidden" id="orderid" value="@Model.OrderID"/>
<input type="hidden" id="orderref" value="@Model.OrderRef"/>
<input type="hidden" id="customerid" value="@Model.CustomerID"/>
<div class="container-fluid">
    <div class="row-fluid">
        <div class="span12">
            <div class="box">
                <div class="box-title">
                    <h3>Order Detail: @orderref</h3>
                </div>
                <div class="row-fluid">
                    <div class="span9">
                        <div class="orderdetail-task">
                            <div class="row-fluid">
                                <fieldset class="span4">
                                    <legend>Shipping detail</legend>
                                    <div class="customerdetailorder">
                                        @Html.Raw(Model.ShippingAddress != null ? Model.ShippingAddress.FullAddress : "")
                                    </div>
                                </fieldset>
                                <fieldset class="span4">
                                    <legend>Billing detail</legend>
                                    <div class="customerdetailorder">
                                        @Html.Raw(Model.BillingAddress != null ? Model.BillingAddress.FullAddress : "")
                                    </div>
                                </fieldset>
                                <fieldset class="span4">
                                    <legend>Special instructions</legend>
                                    <div class="customerdetailorder">
                                        @Html.Raw(Model.SpecialInstructions != null ? Model.SpecialInstructions.Replace("\r\n", "<br>") : "")
                                    </div>
                                </fieldset>
                                @*<fieldset class="span3">
                                    <legend>Customer Notes</legend>
                                    <div class="customerdetailorder">
                                        <form id="fr-CommentNote" style="display: none">
                                            <div class="row-fluid">
                                                <textarea id="txtCommentNote" name="commentnote" class="input-block-level"  required="required" rows="3" style="margin: 0px;"></textarea>
                                                <a class="btn btn-mini"style="padding: 3px 6px; float: right" id="btn-hideCommentNote"> <i class="icon-angle-up"></i></a>
                                                <input type="hidden" name="CustomerId" value="@Model.CustomerID"/>
                                                <button type="submit" class=" btn btn-mini btn-primary" style="padding: 3px 6px;">Submit</button>
                                            </div>
                                        </form>
                                        <a class="btn btn-mini"style="padding: 2px 5px; float: right" id="btn-showCommentNote"><i class="icon-edit"></i></a>
                                        <ul class="unstyled lstCustomerNotes">
                                        @foreach (var note in (Model.Customer??new tblCustomer()).CustomerNotes.OrderByDescending(p=>p.Id))
                                        {
                                            <li>
                                                @Html.Raw(!string.IsNullOrEmpty(note.Notes) ? note.Notes.Replace(System.Environment.NewLine, "<br>") : "")
                                            </li>
                                        }
                                        </ul>
                                    </div>
                                </fieldset>*@

                            </div>
                            <a href="javascript:;" onclick="PopupCenter('/orderview/contactcustomer/@Model.OrderID', 980, 520)" class="btn">Contact customer</a>
                            <a href="javascript:;" onclick="PopupCenter('/orderview/editinstructions/@Model.OrderID', 550, 550)" class="btn pull-right" style="margin-left: 10px;">Edit instructions</a>
                            <a href="javascript:;" onclick="PopupCenter('/orderview/ViewHistoryInstructions?orderref=@Model.OrderRef', 800, 600)" class="btn pull-right" style="margin-left: 10px;">View history</a>
                            <a href="javascript:;" onclick="PopupCenter('/orderview/sendsms/@Model.OrderID', 600, 450)" class="btn pull-right" style="margin-left: 10px;">Send SMS</a>
                            <a href="javascript:;" onclick="PopupCenter('/orderview/updatedetail/@Model.OrderID', 800, 490)" class="btn pull-right" style="margin-left: 10px;">Update detail</a>
                            <a href="javascript:;" onclick="PopupCenter('/ticket/OrderEmailRelationHistory?orderref=@Model.OrderRef', 800, 600)" class="btn pull-right" style="margin-left: 10px;">Related emails</a>
                            <a href="javascript:;" onclick="PopupCenter('/orderview/CustomerNoteRelated?customerid=@Model.CustomerID', 900, 600)" class="btn pull-right" style="margin-left: 10px;">Customer Notes</a>

                            <div class="clearfix"></div>

                            <ul class="tabs tabs-inline tabs-top orderdetail-task-tabs">
                                <li class="active">
                                    <a href="#Tasks" data-toggle="tab">Tasks/Notes(@Model.GetCountTasks())</a>
                                </li>
                                <li>
                                    <a href="#RDM" data-toggle="tab">RDM(@Model.GetCountRDMByOrder())</a>
                                </li>
                                <li>
                                    <a href="#Email" data-toggle="tab">Email history</a>
                                </li>
                                <li>
                                    <a href="#Supplier" data-toggle="tab">Supplier Communication</a>
                                </li>
                                <li>
                                    <a href="#LogHistory" data-toggle="tab">Log History</a>
                                </li>
                                <li>
                                    <a href="#MessageToDriver" data-toggle="tab">Message To Driver</a>
                                </li>
                            </ul>

                            <div class="tab-content padding tab-content-inline tab-content-bottom orderdetail-task-tabs-content" style="height: 240px">
                                <div class="tab-pane active" id="Tasks">
                                    <div class="order-task-scroll tasks fixhead">
                                        <div class="ajax-loading"></div>
                                    </div>
                                    <div class="text-right" style="padding-top: 10px">
                                        <a  href="javascript:;" onclick="PopupCenter('/orderview/addtask/@Model.OrderID', 700, 620)" class="btn">Add task</a>
                                    </div>
                                </div>
                                <div class="tab-pane" id="RDM">
                                    <div class="order-task-scroll rdm"></div>
                                    <div class="text-right" style="padding-top: 10px">
                                        <a  href="javascript:;" onclick="PopupCenter('/rdm/questionnaireaudit/@Model.OrderID', 1200, 600)" class="btn" style="margin-left: 10px">Questionnaire Audit</a>
                                        <a  href="javascript:;" onclick="PopupCenter('/rdm/viewquestionnaire?orderref=@Model.OrderRef', 900, 560)" class="btn" style="margin-left: 10px">View questionnaire</a>
                                        <a  href="javascript:;" onclick="PopupCenter('/rdm/ViewIncompleteRdm/@Model.OrderID', 1200, 600)" class="btn" style="margin-left: 10px">View incomplete RDM</a>
                                    </div>
                                </div>
                                <div class="tab-pane" id="Email">
                                    <div class="order-email-scroll email-history"></div>
                                </div>
                                <div class="tab-pane" id="Supplier">
                                    <div class="order-email-scroll">
                                        <div class="span5 row-fluid">
                                            <form action="/orderview/supplierresendemail" method="POST" class="fr-supplierresendemail margin0">
                                                <div class="row-fluid">
                                                    <div class="span8">...</div>
                                                    @*<div class="span4 text-right">
                                                    <button type="button" class="btn btn-primary">Resend</button>
                                                </div>*@
                                                </div>
                                                <div class="row-fluid">
                                                    <div class="span5">
                                                        <strong>Last Sent</strong>
                                                    </div>
                                                </div>
                                                <div class="row-fluid">
                                                    <div class="span5">
                                                        <strong>Contact Name</strong>
                                                    </div>
                                                    <div class="span7">
                                                        <input type="text" class="input-block-level" />
                                                    </div>
                                                </div>
                                                <div class="row-fluid">
                                                    <div class="span5">
                                                        <strong>Contact Tel</strong>
                                                    </div>
                                                    <div class="span7">
                                                        <input type="text" class="input-block-level" />
                                                    </div>
                                                </div>
                                                <div class="row-fluid">
                                                    <div class="span5">
                                                        <strong>Contact Email</strong>
                                                    </div>
                                                    <div class="span7">
                                                        <input type="text" class="input-block-level" />
                                                    </div>
                                                </div>
                                            </form>
                                        </div>
                                        <div class="span7 supplier"></div>
                                    </div>

                                </div>
                                <div class="tab-pane" id="LogHistory">
                                    <div class="order-email-scroll">
                                        <div class="loghistorydetail">
                                            <div class="span5 row-fluid">
                                                <div class="row-fluid">
                                                    <div class="span4">
                                                        Load Mobile: 
                                                    </div>
                                                    <div class="span8">
                                                        <select onchange="filterLogHistoryByType(this.value)">
                                                            <option value="0">All</option>
                                                            <option value="1">KRM</option>
                                                            <option value="2">LoadMobile</option>
                                                        </select>
                                                    </div>
                                                </div>
                                                <div class="row-fluid">
                                                    <div class="span4">
                                                        AppMobile Picker:
                                                    </div>
                                                    <div class="span8">
                                                        <input type="text" class="input-block-level" disabled="disabled" id="LogHistory-PickerName" value="" />
                                                    </div>
                                                </div>
                                                <p>Extra Information:</p>
                                                <div class="row-fluid">
                                                    <textarea class="input-block-level" disabled="disabled" id="LogHistory-ExtraInfo" rows="3"></textarea>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="span7 loghistory"></div>
                                    </div>
                                </div>
                                <div class="tab-pane" id="MessageToDriver"></div>
                            </div>
                        </div>
                    </div>
                    <div class="span3">
                        <fieldset>
                            <legend>Order summary</legend>
                            <div class="order-summary">
                                <div class="ajax-loading"></div>
                            </div>
                        </fieldset>
                    </div>
                    <div class="row-fluid">
                        <div class="order-items span12">
                            <h5>Order item detail</h5>
                            <div id="lstorder-items">
                                <div class="ajax-loading"></div>
                            </div>
                        </div>
                    </div>
                    <div class="row-fluid">
                        <div class="order-items">
                            <h5>Order item parts/components</h5>
                            <div id="warehouse" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="warehouse" aria-hidden="true">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                                    <h5 id="myModalLabel">Select warehouse</h5>
                                </div>
                                <div class="modal-body">
                                    <div class="text-center">
                                        @Html.DropDownList("Warehouseid")
                                    </div>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-primary btn-warehouse" data-dismiss="modal" aria-hidden="true">Ok</button>
                                </div>
                            </div>
                            <div class="order-items-parts">
                                <a href="#warehouse" role="button" data-toggle="modal" id="choosewarehouse"></a>
                                @*<table class="table table-hover table-bordered table-fix">
                                    <thead>
                                        <tr>
                                            <th><a  style="width: 29px"></a></th>
                                            <th>Action</th>
                                            <th>LoadItemStatus</th>
                                            <th>DeliveryType</th>
                                            <th>Qty</th>
                                            <th>PartID</th>
                                            <th>PartName</th>
                                            <th>SupplierManufacturer</th>
                                            <th>WareHouse</th>
                                            <th>CarrierService</th>
                                            <th>StockAllocatedDate</th>
                                            <th>LoadName</th>
                                            <th>DriveName</th>
                                            <th>DropNumber</th>
                                            <th>DatePicker</th>
                                            <th>OrderItemID</th>
                                            <th>SentStockID</th>
                                            <th>PartVersion</th>
                                        </tr>
                                    </thead>
                                </table>*@
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
</div>
@Html.Partial("Partial/_MessageResult")